Skip to content

Conversation

@strawgate
Copy link
Contributor

@strawgate strawgate commented Dec 19, 2025

Require formatted and runnable examples in docstrings and documentation, and bring the documentation and code up to compliance with these new requirements. Closes #1587

Uses pytest-examples to ensure that examples in docstrings and documentation are properly formatted and runnable with assertions on any print statements in the example. Adds pytest-timeout to the dev dependencies which is used to prevent example tests from running forever if they hit blocking code.

There are ~300 newly passing tests and ~140 skipped tests (examples that are not checked for formatting or if they are runnable).

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@strawgate strawgate changed the title [Draft] Add pytest-examples [Draft] Require formatted and runable examples in docstrings and documentation Dec 20, 2025
@strawgate strawgate changed the title [Draft] Require formatted and runable examples in docstrings and documentation Require formatted and runable examples in docstrings and documentation Dec 20, 2025
@strawgate strawgate changed the title Require formatted and runable examples in docstrings and documentation Require formatted and runnable examples in docstrings and documentation Dec 20, 2025
@strawgate strawgate changed the title Require formatted and runnable examples in docstrings and documentation Enforce working examples in docstrings and documentation Dec 20, 2025
@strawgate strawgate marked this pull request as draft January 17, 2026 04:52
@strawgate
Copy link
Contributor Author

Hey sorry, should have left this in draft, I'll pick this back up and get it ready to be merged

@strawgate strawgate marked this pull request as ready for review January 17, 2026 18:52
@strawgate strawgate requested a review from alexmojaki January 17, 2026 18:53
@strawgate
Copy link
Contributor Author

@alexmojaki thanks for the review, I think this is looking better now.

@strawgate strawgate marked this pull request as draft January 19, 2026 19:01
@strawgate strawgate marked this pull request as ready for review January 19, 2026 19:04
@strawgate
Copy link
Contributor Author

@alexmojaki i did an audit of the 20 uses of hl_lines in the docs, resolved all issues I could find (whether caused by this PR or currently mishighlighted on main), and manually verified the correct lines are highlighted in the served docs with this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces comprehensive testing infrastructure to ensure that code examples in documentation and docstrings are properly formatted and runnable. It uses pytest-examples to validate ~300 examples across the codebase, with ~140 examples appropriately skipped when they require external connections, are incomplete, or would block execution.

Changes:

  • Added pytest-examples and pytest-timeout as dev dependencies to validate documentation examples
  • Created tests/test_docs.py with formatting and execution tests for code examples
  • Updated documentation examples throughout to be properly formatted, with correct import ordering and skip tags
  • Added MkDocs plugin code to strip custom test attributes from rendered documentation

Reviewed changes

Copilot reviewed 71 out of 73 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_docs.py New test file implementing example validation with pytest-examples
pyproject.toml Added pytest-examples>=0.0.18 and pytest-timeout>=2.4.0 to dev dependencies
uv.lock Updated dependency lockfile with new packages and version bumps for dspy and gepa
docs/plugins/main.py Added function to strip custom test attributes from code blocks in rendered docs
logfire/integrations/pydantic.py Fixed import ordering in docstring example
logfire/_internal/main.py Added skip tags to examples requiring external connections and fixed import ordering
docs/**/*.md Extensive formatting fixes including import ordering, skip tags, and consistent quote usage
README.md Updated examples with proper formatting and skip tags
Makefile Added test-update-examples target for updating documentation examples
CONTRIBUTING.md Updated contributor instructions to include new example update command

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pytest-examples to verify documentation examples

2 participants